#include "drv_tim7.h"

//定时器实现LED灯的闪烁
void drv_tim7_init(void)
{	
	TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
	NVIC_InitTypeDef NVIC_InitStruct;

	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);
	
	TIM_TimeBaseInitStruct.TIM_ClockDivision=TIM_CKD_DIV1;//TIM_CKD_DIV1表示不分频
	TIM_TimeBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up;
	TIM_TimeBaseInitStruct.TIM_Period=10000-1;//从0开始计数 重装载值ARR 1s
	TIM_TimeBaseInitStruct.TIM_Prescaler=8400-1;//从0开始计数 预分频器PSC 
	TIM_TimeBaseInit(TIM7,&TIM_TimeBaseInitStruct);

	TIM_ITConfig(TIM7, TIM_IT_Update, ENABLE);//使能TIM7的更新中断（当计数器达到ARR值时触发中断）

	NVIC_InitStruct.NVIC_IRQChannel=TIM7_IRQn;
	NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=1;
	NVIC_InitStruct.NVIC_IRQChannelSubPriority=1;
	NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;

	TIM_Cmd(TIM7,ENABLE);//使能定时器，开始计数
	
	NVIC_Init(&NVIC_InitStruct);
	

}

//void TIM7_IRQHandler(void)
//{
//	if(TIM_GetITStatus(TIM7, TIM_IT_Update))
//	{
//		TIM_ClearITPendingBit(TIM7, TIM_IT_Update);
////		GPIO_ToggleBits(GPIOC, GPIO_Pin_3);
//	}
//		
//}

